package com.tju.resource.oauth.controller.tb;

import com.tju.resource.annotation.Log;
import com.tju.resource.business.tb_retreat.TbRetreatService;
import com.tju.resource.model.TbRetreat;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 退料管理
 */
@RestController
public class TbRetreatController {
    private static final String prefix = "retreat/";
    @Autowired
    private TbRetreatService tbRetreatService;

    /**
     * 查询退料记录
     * @param params 查询参数
     * @return 结果
     */
    @PostMapping(prefix + "list")
    @PreAuthorize("hasAuthority('sys:re:retreat:list')")
    @Log(type = FunctionType.List)
    public Result<Object> selectRetreat(@RequestBody Map<String, String> params) {
        return tbRetreatService.selectRetreat(params);
    }

    /**
     * 添加退料记录
     * @param tbRetreat 参数
     * @return 结果
     */
    @PostMapping(prefix + "add")
    @PreAuthorize("hasAnyAuthority('sys:re:retreat:add','sys:plan:project:back')")
    @Log(type = FunctionType.Add)
    public Result<Object> addRetreat(@RequestBody TbRetreat tbRetreat) {
        return tbRetreatService.addRetreat(tbRetreat);
    }

    /**
     * 修改退料记录
     * @param tbRetreat 参数
     * @return 结果
     */
    @PostMapping(prefix + "edit")
    @PreAuthorize("hasAuthority('sys:re:retreat:edit')")
    @Log(type = FunctionType.Modify)
    public Result<Object> editRetreat(@RequestBody TbRetreat tbRetreat) {
        return tbRetreatService.editRetreat(tbRetreat);
    }

    /**
     * 删除退料记录
     * @param tbRetreat 参数
     * @return 结果
     */
    @PostMapping(prefix + "delete")
    @PreAuthorize("hasAuthority('sys:re:retreat:delete')")
    @Log(type = FunctionType.Delete)
    public Result<Object> deleteRetreat(@RequestBody TbRetreat tbRetreat) {
        return tbRetreatService.deleteRetreat(tbRetreat);
    }
    /**
     * 审核退料记录
     * @param tbRetreat 参数
     * @return 结果
     */
    @PostMapping(prefix + "approve")
    @PreAuthorize("hasAuthority('sys:re:retreat:approve')")
    @Log(type = FunctionType.FirstInstance)
    public Result<Object> approveRetreat(@RequestBody TbRetreat tbRetreat) {
        return tbRetreatService.approveRetreat(tbRetreat);
    }

}
